import pymysql


# 定义全值变量
conn = None
cursor = None

try:
    # 创建连接
    conn = pymysql.connect(host="192.168.110.243", port=3307, user="unet", password='unet2023', database='uandme',
                           charset="utf8")
    # 获取游标
    cursor = conn.cursor()
    # 查询语句
    cursor.execute("SELECT * FROM unet_user ;")
    # 处理结果集
    # 单次提取游标
    result = cursor.fetchone()
    result1 = cursor.fetchone()
    # 游标位置设为0
    cursor.rownumber = 0
    result2 = cursor.fetchall()

    '''
    result = cursor.fetchmany(size)  多次获取   size为获取个数
    result = cursor.fetchall()   获取所有   
    rownumber   可以设置游标位置

    '''
    # 输入结果集
    print("result = ", result)
    print("result1 = ", result1)
    print("result2 = ", result2)
except Exception as err:
    print("发生错误", str(err))
finally:
    # 关闭游标
    cursor.close()
    # 关闭连接
    conn.close()
